let baseUrl = "https://api-hmugo-web.itheima.net/api/public/v1"
let timeout = 5000
function request(method, url, data) {

  return new Promise((resolve, reject) => {
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: baseUrl + url,
      method,
      timeout,
      data: method === "POST" ? JSON.stringify(data) : data,
      success: function (res) {
        wx.hideLoading()
        resolve(res.data.message)
      },
      fail: function (res) {
        wx.hideLoading()
        console.log("请求错误:" + res)
        reject(res)
      }
    })
  })
}
export default request